<?php
/**
 * @version        $Id: admin_action_ok.php 2014年8月20日Z yeshili $
 * @package        YeshiliCRM.Admin
 * @copyright      Copyright (c) 2014 - 2050, YeshiliCRM, Inc.
 * @license        http://help.****.com/YeshiliCRM/help.html
 * @link           http://www.****.com
 */
require_once '../inc/config.php';
require_once 'admin_session.php';
get_rank($_SESSION['id']);
$act = $_GET['act'];
$id =getvar('id');

$fid =getvar('fid');
$title =getvar('title');
$url =getvar('url');
$display =getvar('display');
$rank=getvar('rank');

if($act=='add'){
	$record = array(
		'fid'		=>$fid,
		'title'		=>$title,
		'url'		=>$url,
		'display'		=>$display,
		'rank'		=>$rank,
		'datetime'	=>date("Y-m-d H:i:s")
	);
	$db->insert($GLOBALS[dbprefix].'action',$record);
	get_record('【栏目】'.$title,'add');
	echo "<script>alert('添加成功!');window.location='admin_action.php';</script>";
}
if ($act=='mod'){
	$record = array(
		'fid'		=>$fid,
		'title'		=>$title,
		'url'		=>$url,
		'display'		=>$display,
		'rank'		=>$rank
	);
	$db->update($GLOBALS[dbprefix].'action',$record,'id='.$id);
	get_record('【栏目】'.$title,'mod');
	echo "<script>alert('修改成功!');window.location='admin_action.php';</script>";
}

//删除
if ($act=='del') {
	$sql = get_sql("select id from {pre}action where id=".$id);
	$list0 = $db->getonerow($sql);
	$sql = get_sql("select count(*) as fid from {pre}action where fid=".$list0['id']);
	$list1 = $db->getonerow($sql);
	if($list1['fid']<>0){
		echo "<script>alert('该目录下还存在(".$list1['fid'].")小类，请删除先！');history.go(-1);</script>";
	 }else{
		get_record('【栏目】'.get_field('action','title','id',$id),'del');
	    $db->delete($GLOBALS[dbprefix].'action','id='.$id);
	    echo "<script>alert('删除成功!');history.go(-1);</script>";
	 }
}
?>
